project(cgm_util CXX)

include(CGMMacros)

# User option to build with concurrent execution support.
option(BUILD_WITH_CONCURRENT_SUPPORT "Build Cubit with concurrent execution support" OFF)

set(cgm_util_srcs
  AllocMemManagersList.cpp
  AppUtil.cpp
  ArrayBasedContainer.cpp
  CCubitFile.cpp
  CGMFileOptions.cpp
  CpuTimer.cpp
  Cubit2DPoint.cpp
  CubitBox.cpp
  CubitColor.cpp
  CubitCoordinateSystem.cpp
  CubitDirIterator.cpp
  CubitDynamicLoader.cpp
  CubitEntity.cpp
  CubitEvent.cpp
  CubitEventDispatcher.cpp
  CubitFile.cpp
  CubitFileFEModel.cpp
  CubitFileIOWrapper.cpp
  CubitFileMetaData.cpp
  CubitFileSimModel.cpp
  CubitFileUtil.cpp
  CubitMatrix.cpp
  CubitMessage.cpp
  CubitMessageHandler.cpp
  CubitObservable.cpp
  CubitObserver.cpp
  CubitOperationEvent.cpp
  CubitPlane.cpp
  CubitSparseMatrix.cpp
  CubitString.cpp
  CubitTransformMatrix.cpp
  CubitUndo.cpp
  CubitUtil.cpp
  CubitVector.cpp
  DLList.cpp
  GMem.cpp
  GetLongOpt.cpp
  GfxDebug.cpp
  IntersectionTool.cpp
  MemoryBlock.cpp
  MemoryManager.cpp
  ParamCubitPlane.cpp
  PlanarParamTool.cpp
  RandomMersenne.cpp
  SDLList.cpp
  SettingHandler.cpp
  SettingHolder.cpp
  StubProgressTool.cpp
  TDUPtr.cpp
  TextProgressTool.cpp
  ToolData.cpp
  ToolDataUser.cpp
  TtyProgressTool.cpp)

set(cgm_util_hdrs
  cgm/AbstractTree.hpp
  cgm/AppUtil.hpp
  cgm/ArrayBasedContainer.hpp
  cgm/CCubitFile.hpp
  cgm/CGMFileOptions.hpp
  cgm/CastTo.hpp
  CommandFeedback.hpp
  cgm/CpuTimer.hpp
  cgm/Cubit2DPoint.hpp
  cgm/CubitBox.hpp
  cgm/CubitBoxStruct.h
  cgm/CubitColor.hpp
  cgm/CubitColorConstants.hpp
  cgm/CubitCoordEvent.hpp
  cgm/CubitCoordinateSystem.hpp
  cgm/CubitDefines.h
  cgm/CubitDirIterator.hpp
  cgm/CubitDynamicLoader.hpp
  cgm/CubitEntity.hpp
  CubitEquation.hpp
  cgm/CubitEvent.hpp
  cgm/CubitEventDispatcher.hpp
  cgm/CubitFile.hpp
  cgm/CubitFileFEModel.hpp
  cgm/CubitFileIOWrapper.hpp
  cgm/CubitFileMetaData.hpp
  cgm/CubitFileSimModel.hpp
  cgm/CubitFileUtil.hpp
  cgm/CubitInputFile.hpp
  cgm/CubitLoops.hpp
  cgm/CubitMatrix.hpp
  cgm/CubitMessage.hpp
  cgm/CubitMessageHandler.hpp
  cgm/CubitObservable.hpp
  cgm/CubitObserver.hpp
  cgm/CubitOperationEvent.hpp
  cgm/CubitPlane.hpp
  cgm/CubitPlaneStruct.h
  cgm/CubitSparseMatrix.hpp
  cgm/CubitString.hpp
  cgm/CubitTransformMatrix.hpp
  cgm/CubitUndo.hpp
  cgm/CubitUtil.hpp
  cgm/CubitVector.hpp
  cgm/CubitVectorStruct.h
  cgm/DLIList.hpp
  cgm/DLList.hpp
  cgm/DrawingToolDefines.h
  cgm/DynamicDLIIterator.hpp
  cgm/DynamicTreeIterator.hpp
  cgm/ElementType.h
  ExternalCoordinateSystem.hpp
  cgm/FacetShapeDefs.hpp
  cgm/GMem.hpp
  cgm/GeometryDefines.h
  cgm/GetLongOpt.hpp
  cgm/GfxDebug.hpp
  cgm/IGUIObservers.hpp
  IdHasher.hpp
  cgm/IndexedDouble.hpp
  cgm/IntersectionTool.hpp
  cgm/InvalidEntity.hpp
  cgm/KDDTree.hpp
  cgm/KDDTree.cpp
  cgm/KDDTreeNode.cpp
  cgm/KDDTreeNode.hpp
  cgm/LocalStart.h
  cgm/ManagedPtrVector.hpp
  cgm/MemoryBlock.hpp
  cgm/MemoryManager.hpp
  cgm/OctTree.hpp
  cgm/OctTree.cpp
  cgm/OctTreeCell.hpp
  cgm/OctTreeCell.cpp
  OrderedSet.hpp
  cgm/ParamCubitPlane.hpp
  cgm/ParamTool.hpp
  cgm/PlanarParamTool.hpp
  cgm/PriorityQueue.hpp
  cgm/PriorityQueue.cpp
  cgm/ProgressTool.hpp
  cgm/RStarTree.hpp
  cgm/RStarTree.cpp
  cgm/RStarTreeNode.hpp
  cgm/RStarTreeNode.cpp
  cgm/RTree.hpp
  cgm/RTree.cpp
  cgm/RTreeNode.hpp
  cgm/RTreeNode.cpp
  cgm/RandomMersenne.hpp
  cgm/SDLCAMergePartnerList.hpp
  cgm/SDLList.hpp
  cgm/SettingHandler.hpp
  cgm/SettingHolder.hpp
  cgm/StubProgressTool.hpp
  cgm/TDCellIndex.hpp
  cgm/TDUPtr.hpp
  cgm/TDVector.hpp
  cgm/TextProgressTool.hpp
  cgm/ToolData.hpp
  cgm/ToolDataUser.hpp
  cgm/TtyProgressTool.hpp
  VariableArray.hpp
  cgm/WeightedOctree.hpp
  cgm/WeightedOctree.cpp
  # Generated files:
  "${CMAKE_CURRENT_BINARY_DIR}/cgm/CGMUtilConfigure.h")

set(CGM_UTIL_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
configure_file(
  "${CMAKE_SOURCE_DIR}/config/CGMUtilConfigure.h.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cgm/CGMUtilConfigure.h"
  @ONLY)

if (BUILD_WITH_CONCURRENT_SUPPORT)
  list(APPEND cgm_util_srcs
    CubitConcurrentApi.cpp
    CubitQtConcurrentApi.cpp)
  list(APPEND cgm_util_hdrs
    CubitConcurrentApi.h
    CubitQtConcurrentApi.h)
  find_package(Qt4 REQUIRED QtCore)
  include(${QT_USE_FILE})
endif ()

if (BUILD_WITH_CONCURRENT_SUPPORT)
  link_libraries(${QT_LIBRARIES})
endif ()

include_directories(
    ${CMAKE_CURRENT_BINARY_DIR}/cgm
    ${CMAKE_CURRENT_SOURCE_DIR}/cgm
)

set(cgm_util_target cgm_util PARENT_SCOPE)
link_libraries(${CMAKE_DL_LIBS})

cgm_add_library(cgm_util 0 
  ${cgm_util_srcs})
  #${cgm_util_hdrs}) # FIXME: template recompilation
set_target_properties(cgm_util PROPERTIES LINKER_LANGUAGE CXX)

if (CGM_UTIL_NAME)
  set_target_properties(cgm_util
    PROPERTIES OUTPUT_NAME "${CGM_UTIL_NAME}")
endif ()

if (WIN32)
  cgm_target_link_libraries(cgm_util shlwapi)
endif ()

cgm_install_headers(${cgm_util_hdrs})

